<!--搜索条 begin-->
<script src="__PUBLIC__/js/autocomplete/jquery.autocomplete.js"></script>
<link rel="stylesheet" href="__PUBLIC__/js/autocomplete/jquery.autocomplete.css" />
<php>
/* 切换搜索工具条- 改成php方法 */

//初始化搜索工具条
$search_app	=	APP_NAME;

//初始化当前的工具条状态
if(APP_NAME=='search'){
	$search_app	=	strtolower(MODULE_NAME);
}else if(APP_NAME=='home' && MODULE_NAME!='Index'){
	$search_app	=	'space';
}

//门户工具条状态
$allow_channels	=	array('home','wiki','space','group','ask','bbs');
$allow_enchannels	=	array('enhome','enwiki','enspace','engroup','enask','enbbs');
$current_channel	=	t($_GET['channel']);
if(APP_NAME=='portal' && in_array($current_channel,$allow_channels)){
	$search_app	=	$current_channel;
}

if(APP_NAME=='portal' && in_array($current_channel,$allow_enchannels)){
	$search_app	=	substr($current_channel,2,10);
}

//生成各种类型的按钮
$st		=	L('base_all');
$st1	=	'class="btn_sea cl01" style="padding:0 18px;*padding:0 8px" type="button"';
$st2	=	'class="btn_sea01 cl02" type="button"';

if($search_app=='ask'){
	//设置搜索按钮
	$st		=	L('base_ask');
	$sb1	=	'<input '.$st1.' value="'.L('search_seek_answer').'" onclick="doSearch(\\'ask\\')" />';
	$sb2	=	'<input '.$st2.' value="'.L('search_ask_question').'" onclick="doSearch(\\'ask\\',\\''.U("ask/Index/post").'\\')" />';
}else if($search_app=='bbs'){
	//设置搜索按钮
	$st		=	L('base_bbs');
	$sb1	=	'<input '.$st1.' value="'.L('search_seek_thread').'" onclick="doSearch(\\'bbs\\')" />';
	$sb2	=	'<input '.$st2.' value="'.L('search_post_thread').'" onclick="doSearch(\\'bbs\\',\\''.U("bbs/Index/post",array("class"=>$_GET['class'])).'\\')" />';
}else if($search_app=='wiki'){
	//设置搜索按钮
	$st		=	L('base_wiki');
	$sb1	=	'<input '.$st1.' value="'.L('search_seek_wiki').'" onclick="doSearch(\\'wiki\\')" />';
	$sb2	=	'<input '.$st2.' value="'.L('search_create_wiki').'" onclick="doSearch(\\'wiki\\',\\''.U("wiki/Index/addwiki").'\\')" />';
}else if($search_app=='space' || $search_app=='blog' || $search_app=='profile'){
	//设置搜索按钮
	$st		=	L('base_space');
	$sb1	=	'<input '.$st1.' value="'.L('search_seek_blog').'" onclick="doSearch(\\'space\\')" />';
	$sb2	=	'<input '.$st2.' value="'.L('search_seek_people').'" onclick="doSearch(\\'profile\\')" />';
}else if($search_app=='group'){
	//设置搜索按钮
	$st		=	L('base_group');
	$sb1	=	'<input '.$st1.' value="'.L('search_seek_content').'" onclick="doSearch(\\'group\\')" />';
	$sb2	=	'<input '.$st2.' value="'.L('search_seek_group').'" onclick="doSearch(\\'group\\',\\''.U("group/Search/index").'\\')" />';
}else if($search_app=='document'){
	//设置搜索按钮
	$st		=	L('base_knowledge');
	$sb1	=	'<input '.$st1.' value="'.L('search_seek_document').'" />';
	$sb2	=	'<input '.$st2.' value="'.L('search_upload_document').'" />';
}else{
	//设置搜索按钮
	$st		=	L('base_all');
	$sb1	=	'<input '.$st1.' value="'.L('search_seek_content').'" onclick="doSearch(\\'all\\')" />';
	$sb2	=	'<input '.$st2.' value="'.L('search_seek_people').'" onclick="doSearch(\\'profile\\')" />';
}
</php>
<div class="top_sea">
	<!--搜索条 左圆角-->
	<div class="top_sea_left"> </div>
	<div class="top_sea_main">
		<div class="sea_main_L pl10" id="themelist"> 
			<span class="ash"><a class="ctb_ash" href="javascript:void(0)" onclick="changeTheme(this,'ash','#666666')"></a></span> 
			<span class="blue"><a class="ctb_blue" href="javascript:void(0)" onclick="changeTheme(this,'blue','#006699')"></a></span> 
			<span class="green"><a class="ctb_green" href="javascript:void(0)" onclick="changeTheme(this,'green','#076119')"></a></span> 
			<span class="orange"><a class="ctb_orange" href="javascript:void(0)" onclick="changeTheme(this,'orange','#D64508')"></a></span> 
			<span class="red"><a id="ctb_red" href="javascript:void(0)" onclick="changeTheme(this,'red','#990000')"></a></span> 
		</div>

		<div id="search_bar" class="sea_main_M">
			<!--搜索条 菜单-->
			<div id="search_bar_menu" class="styled-dropdown action-menu">
				<!--搜索条 选中的分类-->
				<p class="label"><span>{$st}</span></p>
				<!--搜索条 待选的菜单-->
				<ul style="display:none;">
					<li><a href="#" <eq name="search_app" value="all">class="current"</eq> urn='all'>{:L('base_all')}</a></li>
					<li><a href="#" <eq name="search_app" value="ask">class="current"</eq> urn='ask'>{:L('base_ask')}</a></li>
					<li><a href="#" <eq name="search_app" value="bbs">class="current"</eq> urn='bbs'>{:L('base_bbs')}</a></li>
					<li><a href="#" <eq name="search_app" value="group">class="current"</eq> urn='group'>{:L('base_group')}</a></li>
					<li><a href="#" <eq name="search_app" value="space">class="current"</eq> urn='space'>{:L('base_space')}</a></li>
					<li><a href="#" <eq name="search_app" value="wiki">class="current"</eq> urn='wiki'>{:L('base_wiki')}</a></li>
					<!-- <li><a href="#" <eq name="search_app" value="document">class="current"</eq> urn='document'>{:L('base_knowledge')}</a></li> -->
				</ul>
			</div>
			<div id="search_bar_button" class="L">
				<!--搜索条 keywords-->
				<span class="pr5 db L" id="search_bar_keyword">
					<input class="sea_box" id="search_input" name="" type="text" value="{$_GET['key']}" onBlur="this.className='sea_box'" onFocus="this.className='sea_box1'"/>
				</span> 
				<!--搜索条 按钮1-->
				<span class="pr5 db L" id="search_bar_button1">
					{$sb1}
				</span> 
				<!--搜索条 按钮2-->
				<span class="pr5 db L" id="search_bar_button2" style="padding-bottom:2px; _margin-top:1px;">
					{$sb2}
				</span>
				<!--搜索条 热门词-->
				<span class="pl10 db L pt5" id="search_bar_hotkeywords"> 
					<a class="mr5" href="{:U('home/cms/help',array('cid'=>44))}" target="_blank">{:L('base_gethelp')}</a>
                    <a href="{:U('portal/Tag/index')}" target="_blank">{:L('base_hottags')}</a>
				</span>
			</div> 
		</div>
	</div>
	<!--搜索条 右圆角-->
	<div class="top_sea_right"> </div>
	<div class="C"> </div>
</div>
<script type="text/javascript">
/* 与搜索条有关的JS */
$(function(){
	//绑定事件：点击label显示或隐藏ul菜单，鼠标离开label菜单消失.
	$('#search_bar_menu .label').bind('click',function(){ 
		$('#search_bar_menu ul').toggle();
		//$('#search_bar_menu .label').bind('mouseout',function(){ $('#search_bar_menu ul').hide() }); 
	});

	//绑定事件：ul菜单的hover事件。取消label菜单的事件。
	$('#search_bar_menu ul').bind('mouseover',function(){
		$(this).show();
		$('#search_bar_menu .label').unbind('mouseout');
	}).bind('mouseout',function(){ $(this).hide() });

	//给下拉li绑定鼠标事件
	$('#search_bar_menu ul li a').each(function(i){
		var u	=	$(this).attr('urn');
		$(this).bind('click',function(){ changeSearchBar(u) });
	});

	//监听回车事件,按回车就执行搜索
	$('#search_input').focus(function(){
		$(this).keyup( function(event){
			if(event.keyCode == 13){
				$('#search_bar_button1 input').click();
			}
		});
	});
	
		$('#search_input').autocomplete('{:U("home/Public/search")}', {
		    minChars:1,
		    width:390,
			max:30,
		    matchContains: true,
		    autoFill: false,
			selectFirst: false,
			dataType: 'json',
			listenKey:0,
		    parse:function(data){
			     var d=data;
			     var rows=new Array();
			     for(var i=0;i<d.length;i++){
			      	rows[rows.length]={data:d[i],value:d[i].key,result:d[i].key,count:d[i].count}
			     }
			     return rows;
		    }, 
		    formatItem: function(data) {
			   	return  " <span class='R pr10'> " + data.count + "</span>" + data.key;
		    },
			onselected: function(row){
				
			},
			nosearchvalue:false
		});

})
//切换搜索工具条- 改成php方法
function changeSearchBar(app){
	//隐藏菜单
	$('#search_bar_menu ul').hide();
	//生成各种类型的按钮
	var st	=	$('#search_bar_menu .label span');
	var sb1	=	$('#search_bar_button1');
	var sb2	=	$('#search_bar_button2');
	var st1	=	'class="btn_sea cl01" style="padding:0 18px;*padding:0 8px" type="button"';
	var st2	=	'class="btn_sea01 cl02" type="button"';
	if(app=='ask'){
		//设置搜索按钮
		st.html('{:L('base_all')}');
		sb1.html('<input '+st1+' value="{:L('search_seek_answer')}" onclick="doSearch(\'ask\')" />');
		sb2.html('<input '+st2+' value="{:L('search_ask_question')}" onclick="doSearch(\'ask\',\'{:U("ask/Index/post")}\')" />');
	}else if(app=='bbs'){
		//设置搜索按钮
		st.html('{:L('base_bbs')}');
		sb1.html('<input '+st1+' value="{:L('search_seek_thread')}" onclick="doSearch(\'bbs\')" />');
		sb2.html('<input '+st2+' value="{:L('search_post_thread')}" onclick="doSearch(\'bbs\',\'{:U("bbs/Index/post")}\')" />');
	}else if(app=='wiki'){
		//设置搜索按钮
		st.html('{:L('base_wiki')}');
		sb1.html('<input '+st1+' value="{:L('search_seek_wiki')}" onclick="doSearch(\'wiki\')" />');
		sb2.html('<input '+st2+' value="{:L('search_create_wiki')}" onclick="doSearch(\'wiki\',\'{:U("wiki/Index/addwiki")}\')" />');
	}else if(app=='space'){
		//设置搜索按钮
		st.html('{:L('base_space')}');
		sb1.html('<input '+st1+' value="{:L('search_seek_blog')}" onclick="doSearch(\'space\')" />');
		sb2.html('<input '+st2+' value="{:L('search_seek_people')}" onclick="doSearch(\'profile\')" />');
	}else if(app=='group'){
		//设置搜索按钮
		st.html('{:L('base_group')}');
		sb1.html('<input '+st1+' value="{:L('search_seek_content')}" onclick="doSearch(\'group\')" />');
		sb2.html('<input '+st2+' value="{:L('search_seek_group')}" onclick="doSearch(\'group\',\'{:U("group/Search/index")}\')" />');
	}else if(app=='document'){
		//设置搜索按钮
		st.html('{:L('base_knowledge')}');
		sb1.html('<input '+st1+' value="{:L('search_seek_document')}" />');
		sb2.html('<input '+st2+' value="{:L('search_upload_document')}" />');
	}else{
		//设置搜索按钮
		st.html('{:L('base_all')}');
		sb1.html('<input '+st1+' value="{:L('search_seek_content')}" onclick="doSearch(\'all\')" />');
		sb2.html('<input '+st2+' value="{:L('search_seek_people')}" onclick="doSearch(\'profile\')" />');
	}
}
//执行搜索
function doSearch(type,url){
	var key	=	$('#search_input').val();
	if(url){
		location.href =	url+"&key="+encodeURIComponent(key);
	}else{
		location.href =	"__ROOT__/?app=search&mod="+type+"&key="+encodeURIComponent(key);
	}
}
//切换样式
function changeTheme(o,type,color){
	$('#themeheader').css('background-color',color);
	$('#themepoint').attr('href',"__PUBLIC__/themes/blue/"+type+"/theme.css");
	$('#logo_image').attr('src',"__PUBLIC__/themes/blue/"+type+"/logo.jpg");
	var date = new Date();
	var ms = 365*24*3600*1000;
	date.setTime(date.getTime() + ms);
	document.cookie = 'TS_theme='+escape(type)+';path=/;domain={:C("COOKIE_DOMAIN")};expires='+date.toGMTString();
	$.each($("#themelist a"),function(i,n){
		$(this).removeAttr('class');
	});
	$(o).attr('class','nb');
}
</script>
<!--搜索 end-->